package com.boang.ks;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Main {
    public static void main(String[] args) {
        GradeManager gradeManager = new GradeManager();
        ExecutorService executor = Executors.newFixedThreadPool(5);

        // Simulate adding grades concurrently
        executor.submit(() -> {
            try {
                gradeManager.addGrade(new Student("Alice", 85.5));
            } catch (DuplicateStudentException e) {
                System.out.println(e.getMessage());
            }
        });

        executor.submit(() -> {
            try {
                gradeManager.addGrade(new Student("Bob", 90.0));
            } catch (DuplicateStudentException e) {
                System.out.println(e.getMessage());
            }
        });

        executor.submit(() -> {
            try {
                gradeManager.addGrade(new Student("Alice", 85.5)); // This should throw an exception
            } catch (DuplicateStudentException e) {
                System.out.println(e.getMessage());
            }
        });

        // Simulate calculating average, finding highest and lowest concurrently
        executor.submit(() -> {
            System.out.println("Average: " + gradeManager.calculateAverage());
        });

        executor.submit(() -> {
            System.out.println("Highest: " + gradeManager.findHighest());
        });

        executor.submit(() -> {
            System.out.println("Lowest: " + gradeManager.findLowest());
        });

        // Shutdown the executor service
        executor.shutdown();
    }
}